import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int num1 = 0;
        int num2 = 1;
        int ret = 0x3f3f3f3f;
        while (num2 < n) {
            int tmp = num1 + num2;
            num1 = num2;
            num2 = tmp;
            ret = Math.max(Math.min(ret, n-num1), 0);
        }
        ret = Math.min(ret, num2-n);
        System.out.println(ret);
    }
}
